
#ifndef _BIT_SLIDER_H_
#define _BIT_SLIDER_H_

#include <stdint.h>
#include "BitBuf.h"

typedef struct {
	uint32_t num_bundles;
	uint32_t *bundles;
	
	uint32_t head, tail;
}BitSlider_T;

static inline uint32_t BitSlider_MaxLength(const BitSlider_T* const slider){
	return slider->num_bundles * BUNDLE_BIT_NUM;
}

static inline uint32_t BitSlider_Length(const BitSlider_T* const slider){
	return slider->tail - slider->head;
}

static inline uint32_t BitSlider_HeadSpace(const BitSlider_T* const slider){
	return slider->head;
}

static inline uint32_t BitSlider_TailSpace(const BitSlider_T* const slider){
	return BitSlider_MaxLength(slider) - slider->tail;
}

static inline void BitSlider_Clear(BitSlider_T* slider, uint32_t head){
	slider->head = slider->tail = head;
}

void BitSlider_Init(BitSlider_T* slider, uint32_t* bundles, uint32_t num_bundles, uint32_t head);

int BitSlider_Add(BitSlider_T* slider, uint8_t val);
int BitSlider_Remove(BitSlider_T* slider, uint8_t* val);

int BitSlider_Push(BitSlider_T* slider, uint8_t val);
int BitSlider_Pop(BitSlider_T* slider, uint8_t* val);

int BitSlider_AddBits(BitSlider_T* slider, uint32_t val, uint32_t num, uint32_t off);
int BitSlider_RemoveBits(BitSlider_T* slider, uint32_t* val, uint32_t num, uint32_t off);

int BitSlider_PushBits(BitSlider_T* slider, uint32_t val, uint32_t num, uint32_t off);
int BitSlider_PopBits(BitSlider_T* slider, uint32_t* val, uint32_t num, uint32_t off);

int BitSlider_AddLSB8(BitSlider_T* slider, uint8_t val);
int BitSlider_AddMSB8(BitSlider_T* slider, uint8_t val);

int BitSlider_RemoveLSB8(BitSlider_T* slider, uint8_t* val);
int BitSlider_RemoveMSB8(BitSlider_T* slider, uint8_t* val);

int BitSlider_PushLSB8(BitSlider_T* slider, uint8_t val);
int BitSlider_PushMSB8(BitSlider_T* slider, uint8_t val);

int BitSlider_PopLSB8(BitSlider_T* slider, uint8_t* val);
int BitSlider_PopMSB8(BitSlider_T* slider, uint8_t* val);

#endif

